package com.design.testdemo.activity;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.design.testdemo.R;

public class LoadingActivity extends AppCompatActivity {

    private ImageView mImageView;

    private Handler mHandler = new Handler();
    private RelativeLayout mRelativeLayout;
    private AnimationDrawable mAnimationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);

        mRelativeLayout = (RelativeLayout) findViewById(R.id.activity_loading);

        mImageView = (ImageView) findViewById(R.id.lottery_animlist);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        mImageView.setImageResource(R.drawable.lottery_animlist);
        mAnimationDrawable = (AnimationDrawable) mImageView.getDrawable();
        mAnimationDrawable.start();

        Toast.makeText(this, "" + mAnimationDrawable.isRunning(), Toast.LENGTH_SHORT).show();

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mAnimationDrawable.stop();

                Toast.makeText(LoadingActivity.this, "" + mAnimationDrawable.isRunning(), Toast.LENGTH_SHORT).show();
            }
        }, 10000);
    }
}
